package com.guchenbo.example.netty4;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @Author guchenbo
 * @Date 2018/10/28.
 */
public class HelloTask implements Runnable {

    protected volatile Thread thread;

    @Override
    public void run() {
        thread = Thread.currentThread();
        System.out.println("start, hello world, i am in " + Thread.currentThread().getName());
        try {
            TimeUnit.SECONDS.sleep(new Random().nextInt(3));
        } catch (InterruptedException e) {
            System.out.println("end by thread.interrupt, hello world, i am in " + Thread.currentThread().getName());
        }
        System.out.println("end, hello world, i am in " + Thread.currentThread().getName());
    }

    public boolean isHelloThread() {
        return Thread.currentThread() == thread;
    }
}
